﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
<Serializable()> Public Class ProjSetCollection
    Inherits System.Collections.CollectionBase
    Implements ICloneable

   
    Private m_Index As Integer = 0

    ''' <summary>
    ''' 添加集合
    ''' </summary>
    ''' <param name="ProjSet"></param>
    ''' <remarks></remarks>
    Public Sub Add(ByVal ProjSet As ProjSet)
        List.Add(ProjSet)
    End Sub
    ''' <summary>
    ''' 删除集合
    ''' </summary>
    ''' <param name="index"></param>
    ''' <remarks></remarks>
    Public Sub Remove(ByVal index As Integer)
        ' Check to see if there is a widget at the supplied index.
        If index > Count - 1 Or index < 0 Then
            ' If no widget exists, a messagebox is shown and the operation is 
            ' cancelled.
            System.Windows.Forms.MessageBox.Show("Index not valid!")
        Else
            ' Invokes the RemoveAt method of the List object.
            List.RemoveAt(index)
        End If
    End Sub

    Public Property Item(ByVal index As Integer) As ProjSet
        Get
            Return CType(List.Item(index), ProjSet)
        End Get
        Set(ByVal value As ProjSet)
            List.Item(index) = value
        End Set
    End Property
    Property Index() As Integer
        Get
            Return Me.m_Index
        End Get
        Set(ByVal value As Integer)
            Me.m_Index = value
        End Set
    End Property

    ''' <summary>
    ''' 返回用户选中的方案个数
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetSelectedProjCount()
        Dim nCount As Integer = 0
        For i As Integer = 0 To Me.Count - 1
            If Me.Item(i).Selected = True Then
                nCount += 1
            End If
        Next
        Return nCount
    End Function
    ''' <summary>
    ''' 返回ProjSetCollection对象的副本
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim objCopy As New ProjSetCollection
        For i As Integer = 0 To Me.List.Count - 1
            objCopy.List.Add(CType(Me.List.Item(i), ProjSet).Clone)
        Next

        objCopy.m_Index = Me.m_Index
        Return objCopy
    End Function

End Class
